import { Component, OnInit } from '@angular/core';
import { RepairService } from "../../repair.service";
import { ActivatedRoute,Router } from '@angular/router';
@Component({
  selector: 'app-order-confirm',
  templateUrl: './order-confirm.component.html',
  styleUrls: ['./order-confirm.component.css',
    '../../../../../assets/css/timeline.css']
})
export class OrderConfirmComponent implements OnInit {
  username:string = '';
  orderId:string = '';
  data:any;
  time:string = '';

  rating = {daochang:1,servicetime:1,repair:1};
  public max: number = 5;
  pingjia:string = '';

  constructor(private _router: Router,private activeRoute:ActivatedRoute,private repairService:RepairService) { }

  ngOnInit() {

    this.activeRoute.params.subscribe(
      params=> {
        this.orderId = this.repairService.orderId = params['orderId'];
        this.username = this.repairService.username;
        this.repairService.getData().subscribe(res => {
          this.data = res.result;
        }, err => console.log(err));
        this.time = this.repairService.getTime();
      }
    );
  }



  save(){
    this.repairService.save('confirm',{
      guzhang_id:this.orderId,
      daochangfen:this.rating.daochang,
      taidufen: this.rating.servicetime,
      weixiufen:this.rating.repair,
      pingjia:this.pingjia
    }).subscribe(res => {
      alert("完成确认！");
      this._router.navigateByUrl('page/repair/order');
    },err => console.log(err));
  }

  cancel(){
    this.repairService.cancel();
  }

}
